Skip to content

Propagate #[allow(dead_code)] on adts to their inherent impls - #157885

Open
mu001999 wants to merge 1 commit into
rust-lang:mainfrom
mu001999-contrib:dead-code/improve
Open

Propagate #[allow(dead_code)] on adts to their inherent impls#157885
mu001999 wants to merge 1 commit into
rust-lang:mainfrom
mu001999-contrib:dead-code/improve

Conversation

@mu001999

@mu001999 mu001999 commented Jun 14, 2026

Copy link
Copy Markdown
Member

View all comments

This PR does:

  1. propagate #[allow(dead_code)] on adts to their inherent impls and impl items
  2. refactor the previous implementation for impl items of traits, and improve the performance (extracted to Refactor the #[allow(dead_code)] propagation for impl items of traits #161571 and Only check #[allow(dead_code)] on the trait #161932)

After the above, there is still some slight perf regressions because we indeed do more things (for inherent impls).

Fixes #149142

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2026
Comment thread compiler/rustc_passes/src/dead.rs Outdated
Comment thread compiler/rustc_passes/src/dead.rs Outdated
@mu001999
mu001999 force-pushed the dead-code/improve branch from 0ff50d6 to 93cdd71 Compare June 14, 2026 14:43
@mu001999

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 15, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 15, 2026
Propagate `#[allow(dead_code)]` on adts to their inherent impls
@rust-bors

rust-bors Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 25aedf1 (25aedf1c569cd8fb010ed559082eacf12d56aaa2, parent: 3daae5e42ec9ba435212987331af1b7b8634fa90)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (25aedf1): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.5% [0.1%, 0.9%] 52
Regressions ❌
(secondary)
0.4% [0.2%, 0.7%] 16
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [-0.2%, 0.9%] 53

Max RSS (memory usage)

Results (primary -2.3%, secondary -1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.9% [-6.9%, -0.9%] 3
Improvements ✅
(secondary)
-1.0% [-1.0%, -1.0%] 1
All ❌✅ (primary) -2.3% [-6.9%, 2.3%] 4

Cycles

Results (secondary 21.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
21.3% [20.3%, 22.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 519.503s -> 518.599s (-0.17%)
Artifact size: 401.51 MiB -> 401.51 MiB (-0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 15, 2026
@mu001999
mu001999 force-pushed the dead-code/improve branch from 93cdd71 to cbc2406 Compare June 16, 2026 16:12
@mu001999

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 16, 2026
Propagate `#[allow(dead_code)]` on adts to their inherent impls
@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 16, 2026
@rust-bors

rust-bors Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 848b0fa (848b0fabbf422f36bd3435a5abda617bf5da7395, parent: 89a99936d9e76a50e8df622e7242190841fd871b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (848b0fa): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 3
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 12
Improvements ✅
(primary)
-0.3% [-0.7%, -0.2%] 14
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 2
All ❌✅ (primary) -0.2% [-0.7%, 0.2%] 17

Max RSS (memory usage)

Results (primary -5.4%, secondary 1.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.3% [1.6%, 5.8%] 3
Improvements ✅
(primary)
-5.4% [-5.4%, -5.4%] 1
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) -5.4% [-5.4%, -5.4%] 1

Cycles

Results (secondary 1.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.4% [4.4%, 4.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.7% [-1.7%, -1.7%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 522.035s -> 522.314s (0.05%)
Artifact size: 401.81 MiB -> 401.26 MiB (-0.14%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 16, 2026
@mu001999
mu001999 force-pushed the dead-code/improve branch from cbc2406 to f1229af Compare June 17, 2026 01:16
@mu001999

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 17, 2026
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang T-lang Relevant to the language team I-lang-radar Items that are on lang's radar and will need eventual work or consideration. labels Jul 22, 2026
@rustbot

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from #157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from #157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
@rust-bors

This comment has been minimized.

RalfJung pushed a commit to RalfJung/miri that referenced this pull request Aug 29, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from rust-lang/rust#157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Aug 31, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from rust-lang/rust#157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
tgross35 pushed a commit to rust-lang/compiler-builtins that referenced this pull request Aug 31, 2026
…kang

Refactor the `#[allow(dead_code)]` propagation for impl items of traits



Extracted from rust-lang/rust#157885.

This PR does the refactor and corrects the previous implementation.

The following will fail currently ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=3279902b2d2e6b0fe75c5af565b1cddd)):
```rust
#![deny(dead_code)]
#![deny(unfulfilled_lint_expectations)]

#[allow(dead_code)]
pub trait Tr {
    fn foo(&self);
}

struct Foo;

impl Tr for Foo {
    fn foo(&self) {
        bar();
    }
}

#[expect(dead_code)]
fn bar() {}

fn main() {}
```

After this PR, we could handle the `#[allow(dead_code)]` propagation correctly, and should get perf improvement.
@rustbot

This comment has been minimized.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 8, 2026
…r, r=chenyukang

Only check `#[allow(dead_code)]` on the trait

I edited on an old branch (on another machine) when trying to resolve the first comment in rust-lang#161571, and then force-pushed it. So it introduced the behavior in rust-lang#157885 partially.

I found this when rebasing rust-lang#157885, and I was expecting a conflict about this.

r? chenyukang
rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
Rollup merge of #161932 - mu001999-contrib:dead-code-refactor, r=chenyukang

Only check `#[allow(dead_code)]` on the trait

I edited on an old branch (on another machine) when trying to resolve the first comment in #161571, and then force-pushed it. So it introduced the behavior in #157885 partially.

I found this when rebasing #157885, and I was expecting a conflict about this.

r? chenyukang
@mu001999

mu001999 commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 9, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 9, 2026
Propagate `#[allow(dead_code)]` on adts to their inherent impls
@rustbot

rustbot commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-bors

rust-bors Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: f20aadf (f20aadf757bb3baa2b92e00b7ead242819037b89)
Base parent: eca445e (eca445e5ae4a6679cc27d3a09106ce245e13a5a6)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f20aadf): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.1%, 0.2%] 8
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.1%, 0.2%] 8

Max RSS (memory usage)

Results (primary 1.2%, secondary -6.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.2% [0.8%, 2.1%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.5% [-6.5%, -6.5%] 1
All ❌✅ (primary) 1.2% [0.8%, 2.1%] 3

Cycles

Results (primary -0.1%, secondary 4.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.7% [0.5%, 1.0%] 5
Regressions ❌
(secondary)
4.0% [2.6%, 6.5%] 3
Improvements ✅
(primary)
-0.6% [-0.7%, -0.4%] 9
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.7%, 1.0%] 14

Binary size

Results (primary 0.0%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.1%] 44
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.1%] 44

Bootstrap: 481.923s -> 479.71s (-0.46%)
Artifact size: 403.28 MiB -> 403.36 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang perf-regression Performance regression. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suppress warnings on dead inherent methods when allowing dead types

7 participants